package cn.sumpu.app.guoguojie.biz.impl;import java.awt.Dimension;import java.io.*;import java.net.*;import java.text.ParseException;import java.text.SimpleDateFormat;import java.util.*;import java.util.regex.*;import javax.annotation.Resource;import javax.servlet.http.HttpServletRequest;import magick.*;import org.apache.commons.lang.StringUtils;import org.slf4j.Logger;import org.slf4j.LoggerFactory;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.transaction.annotation.Transactional;import com.taobao.api.domain.TaobaokeItem;import cn.sumpu.app.guoguojie.biz.*;import cn.sumpu.app.guoguojie.constant.*;import cn.sumpu.app.guoguojie.constant.Expression;import cn.sumpu.app.guoguojie.dao.*;import cn.sumpu.app.guoguojie.domain.*;import cn.sumpu.app.guoguojie.domain.Ext.*;import cn.sumpu.app.guoguojie.util.*;import cn.sumpu.app.guoguojie.util.ImageWeb;import cn.sumpu.app.guoguojie.exception.*;public class DoingBizImpl implements DoingBiz {    private final static Logger logger = LoggerFactory.getLogger(DoingBizImpl.class);    private DoingDao            doingDao;    @Autowired    private ImageBiz            imageBiz;    @Autowired    private MentionBiz          mentionBiz;    @Autowired    private MemberBiz           memberBiz;    @Autowired    private CommentBiz          commentBiz;    @Autowired    private FastextBiz          fastextBiz;    @Autowired    private PictorialBiz        pictorialBiz;    @Resource    private IdentifierBiz       identifierBiz;    @Autowired    private TopBiz              topBiz;    @Autowired    private DoingTagShowBiz     tagBiz;    @Autowired    private DiscussBiz          discussBiz;    @Autowired    private AppconfBiz          appconfBiz;    private String              imageServer;    private String              server;    private String              imageDir;    private String              xtaoAppkey;    private String              xtaoAppsecret;    private String              xtaoPid;    private String              xtaoUrl;    public String getXtaoAppkey() {        return xtaoAppkey;    }    public void setXtaoAppkey(String xtaoAppkey) {        this.xtaoAppkey = xtaoAppkey;    }    public String getXtaoAppsecret() {        return xtaoAppsecret;    }    public void setXtaoAppsecret(String xtaoAppsecret) {        this.xtaoAppsecret = xtaoAppsecret;    }    public String getXtaoPid() {        return xtaoPid;    }    public void setXtaoPid(String xtaoPid) {        this.xtaoPid = xtaoPid;    }    public String getXtaoUrl() {        return xtaoUrl;    }    public void setXtaoUrl(String xtaoUrl) {        this.xtaoUrl = xtaoUrl;    }    public void setImageServer(String imageServer) {        this.imageServer = imageServer;    }    public void setDoingDao(DoingDao doingDao) {        this.doingDao = doingDao;    }    public void setServer(String server) {        this.server = server;    }    public void setImageDir(String imageDir) {        this.imageDir = imageDir;    }    @Override    public ProductBs getProductInfo(String url) throws Exception {        ProductBs productBs = DoingProductUtil.getProductInfo(url, xtaoAppkey, xtaoAppsecret, xtaoPid, xtaoUrl);        return productBs;    }    // 输入一条微博，同时插入一个动态    @Transactional(rollbackForClassName = { "cn.sumpu.app.guoguojie.exception.AppBusinessException" }, timeout = 10)    public void insert(Doing doing) throws AppBusinessException {        doing.setIdentifier(identifierBiz.generateId("doing"));        String content = doing.getContent();        List<String> list = getTopic(content);        for (int i = 0; i < list.size(); i++) {            DoingTopic doingTopic = new DoingTopic();            doingTopic.setIdentifier(identifierBiz.generateId("doing_topic"));            doingTopic.setMember(doing.getMember());            doingTopic.setTopicName(list.get(i));            doingDao.insertTopic(doingTopic);            DoingTopicRelation topicRelation = new DoingTopicRelation();            topicRelation.setIdentifier(identifierBiz.generateId("doing_topic_relation"));            topicRelation.setDoing(doing.getIdentifier());            topicRelation.setTopic(doingTopic.getIdentifier());            doingDao.insertTopicRelation(topicRelation);        }        doingDao.insert(doing);        // doingDao.insertDoingProduct(doingProduct)    }    // 分享商品    @Transactional(rollbackForClassName = { "cn.sumpu.app.guoguojie.exception.AppBusinessException" }, timeout = 10)    public AlertMsg postDoingProduct(final Doing doing, DoingProduct doingProduct, String ip, Boolean isShare, final Member member) throws AppBusinessException {        AlertMsg aMsg = new AlertMsg();        String doingId = identifierBiz.generateId("doing");        doing.setIdentifier(doingId);        doing.setMember(member.getIdentifier());        doing.setPostIp(ip);        if (!Common.empty(doing.getPictorial())) {            doing.setType(DoingType.PICTORIAL.getValue());            DoingPictorial pictorial = pictorialBiz.getPictorialById(doing.getPictorial());            if (pictorial != null && !(pictorial.getFamily().equals(member.getFamily()))) {                aMsg.setCode(AlertMsgCode.FAILURE.getValue());                aMsg.setMsg("你不属于该画报的作者的家庭，不能添加该画报！");                return aMsg;            }        }        String content = doing.getContent();        // 屏蔽关键字        doing.setContent(fastextBiz.antiReplace(doing.getContent()));        doingDao.insert(doing);        // 如果有at的就往提到我的表内插入信息        Set<String> atList = atList(null, content);        for (String family : atList) {            Mention mention = new Mention(identifierBiz.generateId("mention"), doing.getMember(), family, "relayId", doing.getIdentifier(), false, ip);            mentionBiz.addMention(mention);            //			评论未读信息加1            //messageBiz.messageAmount(family, MessageAmountType.AT.getValue());        }        // 插入微博商品信息        if (doingProduct != null) {            doingProduct.setIdentifier(identifierBiz.generateId("doing_product"));            doingProduct.setDoing(doing.getIdentifier());            doingProduct.setMember(doing.getMember());            //切割商品图片            cutImg(doingProduct, member.getIdentifier());            addProduct(doingProduct);        }        //更新画报数量        if (!Common.empty(doing.getPictorial())) {            DoingPictorial pictorial = new DoingPictorial();            pictorial.setIdentifier(doing.getPictorial());            pictorial.setProAmount(1);            pictorial.setGmtModified(new Date());            pictorialBiz.updatePictorial(pictorial);        }        if (isShare != null && isShare) {            final DoingProduct dp1 = doingProduct;            new Thread(new Runnable() {                @Override                public void run() {                    postWeiboOut(doing, dp1, null, member, doing.getPostIp());                }            }).start();        }        aMsg.setMsg("success");        aMsg.setCode(doingId);        return aMsg;    }    // 发送微博到新浪微博和腾讯微博    private void postWeiboOut(Doing doing, DoingProduct product, DoingPicture picture, Member member, String clientIP) {        try {            String picurl = "";            String picurl2 = "";            Boolean isHaveUrl = Common.checkUrl(doing.getContent());            String content = doing.getContent();            content = URLDecoder.decode(content, "UTF-8");            List<MemberOutAccount> outAccountList = member.getOutAccountList();            if (!Common.empty(product)) {                picurl = product.getPicUrl();                picurl2 = imageDir + "/" + product.getPicThumb() + "_468xXXX.jpg";                if (isHaveUrl == false) {                    content = content + server + "dt.htm?id=" + doing.getIdentifier();                }            } else if (Common.empty(product) && !Common.empty(picture)) {                String picImageSer = picture.getImageServer();                picurl = picImageSer + picture.getPicUrl();                picurl2 = imageDir + "/" + picture.getPicUrl();// FIXME 这段代码对环境不兼容，只能在生产环境使用，等腾讯新的接口（支持网络图片）开发出来后，需要修复。                if (isHaveUrl == false) {                    content = content + server + "dt.htm?id=" + doing.getIdentifier();                }            } else if (Common.empty(product) && Common.empty(picture)) {                picurl = null;            }            post(clientIP, picurl, picurl2, content, outAccountList);        } catch (Exception e) {            e.printStackTrace();        }    }    private void post(String clientIP, String picurl, String picurl2, String content, List<MemberOutAccount> outAccountList)                                                                                                                            throws UnsupportedEncodingException,                                                                                                                            IOException, Exception {        for (MemberOutAccount m : outAccountList) {            if (m.getOutAccountType().equals("01") && m.getEnabled()) {                // 绑定到新浪微博就发到新浪微博                if (Common.empty(picurl)) {                    SinaWeibo.sendMessage2Sina(URLEncoder.encode(content, "UTF-8"), m.getAccessToken(), m.getAccessSecret());                } else {                    SinaWeibo.sendPic2Sina(URLEncoder.encode(content, "UTF-8"), picurl, m.getAccessToken(), m.getAccessSecret());                }            }            if (m.getOutAccountType().equals("03") && m.getEnabled()) {                // 绑定到腾讯微博就发到腾讯微博                if (Common.empty(picurl2)) {                    TencentWeibo.sendMessage2TencentWeibo(content, m.getAccessToken(), m.getAccessSecret(), clientIP);                } else {                    TencentWeibo.sendMessagePicTencentWeibo(content, picurl2, m.getAccessToken(), m.getAccessSecret(), clientIP);                }            }        }    }    public void post2Weibo(String content, String picurl) throws AppBusinessException {        try {            SinaWeibo.sendLocalPicSina(content, picurl, "864fef527eaf025fd47110e35f32d35b", "9c62d5d7373fa378b8de44a8c8df6b39");        } catch (Exception e) {            e.printStackTrace();        }    }    private List<String> getTopic(String content) {        List<String> list = new ArrayList<String>();        String p1 = "\\#[^\\#\\#]{1,}\\#";        Pattern p = Pattern.compile(p1);        Matcher m = p.matcher(content);        while (m.find()) {            String s = m.group().trim();            int firstIndex = s.indexOf("#");            int lastIndex = s.lastIndexOf("#");            String d = s.substring(firstIndex + 1, lastIndex);            list.add(d);        }        return list;    }    // 转发微博    @Transactional(rollbackForClassName = { "cn.sumpu.app.guoguojie.exception.AppBusinessException" }, timeout = 10)    public void doingForward(String forwardId, String content, boolean commentFamily, boolean commentRootFamily, Member member, String ip)                                                                                                                                          throws AppBusinessException {        Doing forwardDoing = getDoingById(forwardId);        //        // 原文转发次数+1        //        doingDao.updateForwards(forwardDoing.getRootId());        //        // 被转发的微博转发次数+1        //        doingDao.updateForwards(forwardId);        Doing doing = new Doing();        String doingId = identifierBiz.generateId("doing");        doing.setIdentifier(doingId);        doing.setMember(member.getIdentifier());        doing.setFamily(member.getFamily());        doing.setContent(content);        doing.setType(DoingType.FORWARD.getValue());        doing.setRootId(Common.empty(forwardDoing.getRootId()) ? forwardId : forwardDoing.getRootId());        doing.setToId(forwardId);        doing.setPostIp(ip);        doing.setOwner(member.getFamily());        doing.setOwnerType(OwnerType.FAMILY.getValue());        doingDao.insert(doing);        if (commentFamily || commentRootFamily) {            Comment comment = new Comment();            comment.setIdentifier(identifierBiz.generateId("comment"));            comment.setMember(member.getIdentifier());            comment.setOwner(member.getOwner());            comment.setOwnerType(member.getOwnerType());            comment.setCommentIdType("doingid");            comment.setCommentId(forwardDoing.getIdentifier());            comment.setContent(content);            comment.setPostIp(ip);            comment.setToFamily(forwardDoing.getOwner());            // 同时评论该条微博            if (commentFamily) {                commentBiz.insert(comment);            }            // 同时评论原微博            if (commentRootFamily) {                comment.setIdentifier(identifierBiz.generateId("comment"));                comment.setCommentId(forwardDoing.getRootId());                comment.setToFamily(forwardDoing.getOwner());                commentBiz.insert(comment);            }        }        // at所有的家庭        atFamilys(member, forwardDoing, doingId, ip, content);    }    public void atFamilys(Member member, Doing forwardDoing, String createDoingId, String ip, String content) throws AppBusinessException {        Mention mention = new Mention(identifierBiz.generateId("mention"), member.getIdentifier(), forwardDoing.getOwner(), "relayId", createDoingId, false, ip);        Set<String> atList = new HashSet<String>();        // 当前被转发的家庭号        atList.add(forwardDoing.getOwner());        // 原文家庭号        String type = forwardDoing.getType();        if (DoingType.FORWARD.getValue().equals(type) || DoingType.REPLY.getValue().equals(type)) {            if (forwardDoing.getRootDoing() != null) {                atList.add(forwardDoing.getRootDoing().getOwner());            }        }        // 内容中含有@的家庭号        atList(atList, content);        for (String family : atList) {            mention.setIdentifier(identifierBiz.generateId("mention"));            mention.setFamily(family);            if (!member.getOwner().equals(family)) {                mentionBiz.addMention(mention);            }        }    }    public Set<String> atList(Set<String> atList, String content) throws AppBusinessException {        if (atList == null) {            atList = new HashSet<String>();        }        Pattern p = Pattern.compile("@[\\u4e00-\\u9fa5\\w\\-]+"); // \s 正则表达式 空格        Matcher m = p.matcher(content);        while (m.find()) {            String title = m.group();            String nickname = title.substring(1);            Member member = memberBiz.getMemberNickname(nickname);            if (member != null) {                atList.add(member.getFamily());            }        }        return atList;    }    public void update(Doing doing) throws AppBusinessException {        doingDao.update(doing);    }    public Doing getDoingByMember(String member) throws AppBusinessException {        return doingDao.getDoingByMember(member);    }    public Doing getDoingByFamily(String family) throws AppBusinessException {        return doingDao.getDoingByFamily(family);    }    public Doing getDoingById(String id) throws AppBusinessException {        Doing doing = doingDao.getDoingById(id);        if (doing != null) {            if (DoingType.FORWARD.getValue().equals(doing.getType()) || DoingType.REPLY.getValue().equals(doing.getType())) {                doing.setRootDoing(getDoingById(doing.getRootId()));            }        }        return doing;    }    @Override    public Doing getRootDoingById(String id) throws AppBusinessException {        Doing doing = doingDao.getDoingById(id);        if (doing != null) {            if (DoingType.FORWARD.getValue().equals(doing.getType())) {                Doing rootDoing = doingDao.getDoingById(doing.getRootId());                if (rootDoing == null) {                    return rootDoing = new Doing();                }                rootDoing.setBaseType(DoingType.FORWARD.getValue());                return rootDoing;            }        }        return null;    }    public List<Doing> getDoingList(Map<String, Object> map) throws AppBusinessException {        return doingDao.getDoingList(map);    }    @Override    public int getDoingListCount(String family) throws AppBusinessException {        Map<String, Object> map = new HashMap<String, Object>();        map.put("owner", family);        map.put("ownerType", OwnerType.FAMILY.getValue());        return doingDao.getDoingListCount(map);    }    @Transactional(rollbackForClassName = { "cn.sumpu.app.guoguojie.exception.AppBusinessException" }, timeout = 10)    public void deleteDoing(String family, String id) throws AppBusinessException {        Map<String, Object> map = new HashMap<String, Object>();        map.put("identifier", id);        map.put("family", family);        Doing delDoing = doingDao.getDoingById(id);        if (delDoing != null && family.equals(delDoing.getOwner())) {            //更新画报数量            if (Common.notEmptyStr(delDoing.getPictorial())) {                int picAmount = -getPicCountByDoing(id);                int proAmount = -getProCountByDoing(id);                DoingPictorial p = new DoingPictorial();                p.setIdentifier(delDoing.getPictorial());                p.setPicAmount(picAmount);                p.setProAmount(proAmount);                //		p.setGmtModified(new Date());                pictorialBiz.updatePictorial(p);            }            doingDao.deleteDoing(map);            // 删除图片和商品信息            deleteDoingPicture(id);            deleteDoingProduct(id);        } else {            throw new AppBusinessException("你没有权限删除该微博！");        }    }    @Override    public PageModel getDoingModel(String family, Integer page) throws AppBusinessException {        Map<String, Object> map = new HashMap<String, Object>();        map.put("owner", family);        map.put("ownerType", OwnerType.FAMILY.getValue());        Integer startId = (page - 1) * Common.PAGE_SIZE_DOING;        map.put("startId", startId);        map.put("pageSize", Common.PAGE_SIZE_DOING);        List<Doing> doingList = doingDao.getDoingList(map);        if (doingList != null && doingList.size() > 0) {            for (Doing doing : doingList) {                String type = doing.getType();                if (DoingType.FORWARD.getValue().equals(type)) {                    Doing rootDoing = getDoingById(doing.getRootId());                    doing.setRootDoing(rootDoing);                }            }        }        int count = doingDao.getDoingListCount(map);        PageModel pm = new PageModel();        pm.setCurrentPage(page);        pm.setList(doingList);        pm.setPageSize(Common.PAGE_SIZE_DOING);        pm.setTotalRecord(count);        pm.setTotalPage((count + Common.PAGE_SIZE_DOING - 1) / Common.PAGE_SIZE_DOING);        return pm;    }    @Override    public List<DoingExt> getDoingByTopic(Map<String, Object> map) throws AppBusinessException {        return doingDao.getDoingByTopic(map);    }    @Override    public void insertTopic(DoingTopic doingTopic) throws AppBusinessException {        doingDao.insertTopic(doingTopic);    }    @Override    public void insertTopicRelation(DoingTopicRelation topicRelation) throws AppBusinessException {        doingDao.insertTopicRelation(topicRelation);    }    @Override    public int getDoingCountByTopic(Map<String, Object> map) throws AppBusinessException {        return doingDao.getDoingCountByTopic(map);    }    @Override    public PageModel getDoingByKeywords(Integer page, String keywords) throws AppBusinessException {        String key = transfer(keywords);        Map<String, Object> map = new HashMap<String, Object>();        map.put("startId", (page - 1) * Common.PAGE_SIZE);        map.put("pageSize", Common.PAGE_SIZE);        map.put("keywords", "%" + key + "%");        int count = doingDao.countDoingByKeywords(map);        PageModel pm = new PageModel();        pm.setCurrentPage(page);        pm.setList(doingDao.getDoingByKeywords(map));        pm.setPageSize(Common.PAGE_SIZE);        pm.setTotalRecord(count);        pm.setTotalPage((count + Common.PAGE_SIZE - 1) / Common.PAGE_SIZE);        return pm;    }    private static String transfer(String keywords) {        if (keywords.contains("%") || keywords.contains("_")) {            keywords = keywords.replaceAll("\\\\", "\\\\\\\\").replaceAll("\\%", "\\\\%").replaceAll("\\_", "\\\\_");        }        return keywords;    }    /**     * author Bruce Zhang     *      * @return 取得20个家庭最新的的一条微博     * @throws AppBusinessException     */    @Override    public List<Doing> getDoingNewest() throws AppBusinessException {        return doingDao.getDoingNewest();    }    /**     * author Bruce Zhang     *      * @param map     *            参数集合（1.doorplate:门牌号 2.title:图片标题 3.startTime:开始时间     *            4.endTime:结束时间）     * @return 根据条件查询照片列表     * @throws AppBusinessException     */    @Override    public PageModel getDoingByCondition(String keyword, String keywordType, String product, String type, String startTime, String endTime, Integer page,                                         String isPage) throws AppBusinessException {        int pageSize = 20;        if (page == null || page <= 0) {            page = 1;        }        Map<String, Object> map = new HashMap<String, Object>();        map.put("product", product);        map.put("type", type);        map.put("keyword", keyword);        map.put("keywordType", keywordType);        map.put("startTime", DateUtil.parseDate(startTime));        map.put("endTime", DateUtil.parseDate(endTime));        int count = doingDao.getDoingCountByCondition(map);        if ("yes".equals(isPage)) {            map.put("startId", (page - 1) * pageSize);            map.put("pageSize", pageSize);        }        List<Doing> pList = doingDao.getDoingByCondition(map);        PageModel pm = new PageModel();        pm.setCurrentPage(page);        pm.setList(pList);        pm.setPageSize(pageSize);        pm.setTotalRecord(count);        if ("yes".equals(isPage)) {            pm.setTotalPage((count + pageSize - 1) / pageSize);        }        return pm;    }    // 根据DoingId集合批量屏蔽照片    @Override    public void updateByDoingIdList(String idList, Boolean enabled) throws AppBusinessException {        Map<String, Object> map = new HashMap<String, Object>();        map.put("identifier", idList);        map.put("enabled", enabled);        doingDao.updateByDoingIdList(map);        // 屏蔽转播的同时屏蔽提到我家的        mentionBiz.updateMentionByCondition(enabled, idList, "relayId");    }    // 根据DoingId集合批量删除照片    @Override    public void deleteByDoingIdList(String idList) throws AppBusinessException {        Map<String, Object> map = new HashMap<String, Object>();        map.put("identifier", idList);        doingDao.deleteByDoingIdList(map);    }    // 根据微博的标签查询微博    @Override    public PageModel getDoingListByTag(String systemTag, Integer page, String doingId, Integer times, Integer minPrice, Integer maxPrice)                                                                                                                                         throws AppBusinessException {        // 延迟时间        Date time = DateUtil.parseDate(Common.getTargetTime("时", 3));        int pageSize = 96; //一页取多少条        int allTimes = 3; //一页分多少次取        if (page == null || page <= 0) {            page = 1;        }        if (times == null || times <= 0) {            times = 1;        }        systemTag = Common.notEmptyStr(systemTag) ? "%" + systemTag + "%" : null;        Map<String, Object> map = new HashMap<String, Object>();        map.put("systemTag", systemTag);        map.put("identifier", doingId);        map.put("delayTime", time);        map.put("minPrice", minPrice);        map.put("maxPrice", maxPrice);        int count = getDoingCountByTag(systemTag, time, minPrice, maxPrice);        map.put("startId", (page - 1) * pageSize + (times - 1) * (pageSize / allTimes));        map.put("pageSize", pageSize / allTimes);        List<Doing> pList = doingDao.getDoingListByTag(map);        PageModel pm = new PageModel();        pm.setCurrentPage(page);        pm.setList(pList);        pm.setPageSize(pageSize);        pm.setTotalRecord(count);        pm.setTotalPage((count + pageSize - 1) / pageSize);        return pm;    }    // 根据微博的标签查询微博总条数    @Override    public Integer getDoingCountByTag(String tag, Date delayTime, Integer minPrice, Integer maxPrice) throws AppBusinessException {        Map<String, Object> map = new HashMap<String, Object>();        map.put("systemTag", tag);        map.put("delayTime", delayTime);        map.put("minPrice", minPrice);        map.put("maxPrice", maxPrice);        return doingDao.getDoingCountByTag(map);    }    // 根据微博的ID取得两条该微博的评论    @Override    public List<Comment> getCommentListByDoing(String doingId) throws AppBusinessException {        Map<String, Object> map = new HashMap<String, Object>();        map.put("doingId", doingId);        return doingDao.getCommentListByDoing(map);    }    @Override    public void deleteDoingProduct(String doing) throws AppBusinessException {        Map<String, Object> map = new HashMap<String, Object>();        map.put("doing", doing);        doingDao.deleteDoingProduct(map);    }    @Override    public List<DoingProduct> getDoingProductList(String doing) throws AppBusinessException {        Map<String, Object> map = new HashMap<String, Object>();        map.put("doing", doing);        return doingDao.getDoingProductList(map);    }    @Override    public void insertDoingProduct(DoingProduct doingProduct) throws AppBusinessException {        doingDao.insertDoingProduct(doingProduct);    }    @Override    public void deleteDoingPicture(String doing) throws AppBusinessException {        Map<String, Object> map = new HashMap<String, Object>();        map.put("doing", doing);        doingDao.deleteDoingPicture(map);    }    @Override    public List<DoingPicture> getDoingPictureList(String doing) throws AppBusinessException {        Map<String, Object> map = new HashMap<String, Object>();        map.put("doing", doing);        return doingDao.getDoingPictureList(map);    }    @Override    public void insertDoingPicture(DoingPicture doingPicture) throws AppBusinessException {        if (Common.empty(doingPicture))            return;        doingPicture.setIdentifier(identifierBiz.generateId("doing_picture"));        doingDao.insertDoingPicture(doingPicture);    }    // 根据频道查询商品列表    @Override    public PageModel getDoingListByChannel(String channel, String systemTag, Integer page, Integer times, Integer minPrice, Integer maxPrice)                                                                                                                                             throws AppBusinessException {        int allTimes = 3; //一页分多少次取         int pageSize = 96; //一页显示多少条        if (page == null || page <= 0) {            page = 1;        }        if (times == null || times <= 0) {            times = 1;        }        systemTag = Common.notEmptyStr(systemTag) ? "%" + systemTag + "%" : null;        Map<String, Object> map = new HashMap<String, Object>();        map.put("channel", channel);        map.put("systemTag", systemTag);        map.put("minPrice", minPrice);        map.put("maxPrice", maxPrice);        int count = getDoingCountByChannel(channel, systemTag, minPrice, maxPrice);        map.put("startId", (page - 1) * pageSize + (times - 1) * (pageSize / allTimes));        map.put("pageSize", pageSize / allTimes);        List<Doing> pList = doingDao.getDoingListByChannel(map);        PageModel pm = new PageModel();        pm.setCurrentPage(page);        pm.setList(pList);        pm.setPageSize(pageSize);        pm.setTotalRecord(count);        pm.setTotalPage((count + pageSize - 1) / pageSize);        return pm;    }    // 根据频道查询商品列表长度    @Override    public Integer getDoingCountByChannel(String channel, String systemTag, Integer minPrice, Integer maxPrice) throws AppBusinessException {        Map<String, Object> map = new HashMap<String, Object>();        map.put("channel", channel);        map.put("systemTag", systemTag);        map.put("minPrice", minPrice);        map.put("maxPrice", maxPrice);        return doingDao.getDoingCountByChannel(map);    }    // 童鞋配饰的格子    @Override    public List<Doing> getDoingGrid(String sql) throws AppBusinessException {        Map<String, Object> map = new HashMap<String, Object>();        map.put("tag", sql);        return doingDao.getDoingGrid(map);    }    // 根据频道查询帖子    @Override    public List<Doing> getPostsListByChannel(String channel, String status, Integer number) throws AppBusinessException {        Map<String, Object> map = new HashMap<String, Object>();        map.put("channel", channel);        map.put("status", status);        map.put("startId", 0);        map.put("pageSize", number);        return doingDao.getPostsListByChannel(map);    }    public void enterWeiBo(String ownerType, HttpServletRequest request) throws AppBusinessException {        String doingTitle = "想跟邻居分享什么新鲜事？";        if (Common.empty(ownerType)) {            ownerType = OwnerType.FAMILY.getValue();        }        if (ownerType.equalsIgnoreCase(OwnerType.FAMILY.getValue())) {            doingTitle = "想跟邻居分享什么新鲜事？";        } else if (ownerType.equalsIgnoreCase(OwnerType.COMPANY.getValue())) {            doingTitle = "想跟用户分享什么新鲜事？";        }        request.setAttribute("doingTitle", doingTitle);        Member member = (Member) request.getSession().getAttribute("member");        Doing doing = getDoingByMember(member.getIdentifier());        Map<String, String> expressionMap = Expression.cache;        request.setAttribute("expressionMap", expressionMap);        request.setAttribute("doing", doing);        request.setAttribute("ownerType", ownerType);    }    @Override    public void familyDoing(Integer page, HttpServletRequest request) throws AppBusinessException {        Member member = (Member) request.getSession().getAttribute("member");        if (page == null) {            page = 1;        }        try {            PageModel pageModel = getDoingModel(member.getFamily(), page);            request.setAttribute("pageModel", pageModel);        } catch (Exception e) {            e.printStackTrace();        }    }    @Override    public void followDoingList(Integer page, HttpServletRequest request) throws AppBusinessException {        Member member = (Member) request.getSession().getAttribute("member");        if (page == null) {            page = 1;        }        try {            PageModel pageModel = getFollowDoingList(page, member.getFamily());            request.setAttribute("pageModel", pageModel);        } catch (Exception e) {            e.printStackTrace();        }    }    @Override    public void cancelFollow(String family, String follow) throws AppBusinessException {        Map<String, Object> map = new HashMap<String, Object>();        map.put("family", family);        map.put("follow", follow);        doingDao.deleteFollow(map);    }    @Override    public void addFollow(String family, String follow, String member) throws AppBusinessException {        Map<String, Object> map = new HashMap<String, Object>();        map.put("family", family);        map.put("follow", follow);        map.put("member", member);        doingDao.insertFollow(map);        //		评论未读信息加1        //messageBiz.messageAmount(follow, MessageAmountType.FANS.getValue());    }    @Override    public void removeFans(String family, String fans) throws AppBusinessException {        Map<String, Object> map = new HashMap<String, Object>();        map.put("family", fans);        map.put("follow", family);        doingDao.deleteFollow(map);    }    @Override    public int getFansCount(String family) throws AppBusinessException {        Map<String, Object> map = new HashMap<String, Object>();        map.put("follow", family);        return doingDao.getFollowCount(map);    }    @Override    public int getFollowCount(String family) throws AppBusinessException {        Map<String, Object> map = new HashMap<String, Object>();        map.put("family", family);        return doingDao.getFollowCount(map);    }    @Override    public PageModel getFansList(Integer page, String taFamily, String meFamily) throws AppBusinessException {        if (meFamily == null)            meFamily = "";        int pageSize = Common.PAGE_SIZE_FOLLOW;        Map<String, Object> map = new HashMap<String, Object>();        map.put("family", taFamily);        map.put("meFamily", meFamily);        int count = getFansCount(taFamily);        map.put("startId", (page - 1) * pageSize);        map.put("pageSize", pageSize);        List<FollowFans> pList = doingDao.getFansList(map);        PageModel pm = new PageModel();        pm.setCurrentPage(page);        pm.setList(pList);        pm.setPageSize(pageSize);        pm.setTotalRecord(count);        pm.setTotalPage((count + pageSize - 1) / pageSize);        return pm;    }    @Override    public PageModel getFollowList(Integer page, String taFamily, String meFamily) throws AppBusinessException {        if (meFamily == null) {            meFamily = "";        }        int pageSize = Common.PAGE_SIZE_FOLLOW;        Map<String, Object> map = new HashMap<String, Object>();        map.put("family", taFamily);        map.put("meFamily", meFamily);        int count = getFollowCount(taFamily);        map.put("startId", (page - 1) * pageSize);        map.put("pageSize", pageSize);        List<FollowFans> pList = doingDao.getFollowList(map);        PageModel pm = new PageModel();        pm.setCurrentPage(page);        pm.setList(pList);        pm.setPageSize(pageSize);        pm.setTotalRecord(count);        pm.setTotalPage((count + pageSize - 1) / pageSize);        return pm;    }    @Override    public PageModel getFollowDoingList(Integer page, String family) throws AppBusinessException {        if (page == null) {            page = 1;        }        int pageSize = Common.PAGE_SIZE_DOING;        Map<String, Object> map = new HashMap<String, Object>();        map.put("family", family);        map.put("ownerType", OwnerType.FAMILY.getValue());        int count = doingDao.getFollowDoingListCount(map);        map.put("startId", (page - 1) * pageSize);        map.put("pageSize", pageSize);        List<Doing> doingList = doingDao.getFollowDoingList(map);        for (Doing doing : doingList) {            String type = doing.getType();            if (DoingType.FORWARD.getValue().equals(type) || DoingType.REPLY.getValue().equals(type) || DoingType.LOVE.getValue().equals(type)) {                Doing rootDoing = getDoingById(doing.getRootId());                doing.setRootDoing(rootDoing);            } else if (DoingType.PICTORIAL.getValue().equals(doing.getType())) {                doing.setPictorialObj(pictorialBiz.getPictorialById(doing.getPictorial()));            }        }        PageModel pm = new PageModel();        pm.setCurrentPage(page);        pm.setList(doingList);        pm.setPageSize(pageSize);        pm.setTotalRecord(count);        pm.setTotalPage((count + pageSize - 1) / pageSize);        return pm;    }    @Override    public PageModel getDoingListByIds(Set<String> idList, Integer page) throws AppBusinessException {        int pageSize = Common.PAGE_SIZE_DOING;        StringBuffer idtmp = new StringBuffer();        int i = 0;        for (String id : idList) {            if (i != 0) {                idtmp.append(",");            }            idtmp.append("'");            idtmp.append(id);            idtmp.append("'");            i++;        }        String ids = idtmp.toString();        if (ids.length() <= 0) {            ids = "''";        }        Map<String, Object> map = new HashMap<String, Object>();        map.put("ids", ids);        int count = doingDao.getDoingListByIdsCount(map);        map.put("startId", (page - 1) * pageSize);        map.put("pageSize", pageSize);        List<Doing> doingList = doingDao.getDoingListByIds(map);        PageModel pm = new PageModel();        pm.setCurrentPage(page);        pm.setList(doingList);        pm.setPageSize(pageSize);        pm.setTotalRecord(count);        pm.setTotalPage((count + pageSize - 1) / pageSize);        return pm;    }    @Override    public PageModel getDoingListByDoingIds(Set<String> idList, Integer page) throws AppBusinessException {        int pageSize = Common.PAGE_SIZE_DOING;        StringBuffer idtmp = new StringBuffer();        int i = 0;        for (String id : idList) {            if (i != 0) {                idtmp.append(",");            }            idtmp.append("'");            idtmp.append(id);            idtmp.append("'");            i++;        }        String ids = idtmp.toString();        if (ids.length() <= 0) {            ids = "''";        }        Map<String, Object> map = new HashMap<String, Object>();        map.put("ids", ids);        int count = doingDao.getDoingListByDoingIdsCount(map);        map.put("startId", (page - 1) * pageSize);        map.put("pageSize", pageSize);        List<Doing> doingList = doingDao.getDoingListByDoingIds(map);        PageModel pm = new PageModel();        pm.setCurrentPage(page);        pm.setList(doingList);        pm.setPageSize(pageSize);        pm.setTotalRecord(count);        pm.setTotalPage((count + pageSize - 1) / pageSize);        return pm;    }    @Override    public PageModel getProductListByProductIds(Set<String> idList, Integer page) throws AppBusinessException {        int pageSize = Common.PAGE_SIZE_DOING;        StringBuffer idtmp = new StringBuffer();        int i = 0;        for (String id : idList) {            if (i != 0) {                idtmp.append(",");            }            idtmp.append("'");            idtmp.append(id);            idtmp.append("'");            i++;        }        String ids = idtmp.toString();        if (ids.length() <= 0) {            ids = "''";        }        Map<String, Object> map = new HashMap<String, Object>();        map.put("ids", ids);        int count = doingDao.getProductListByProductIdsCount(map);        map.put("startId", (page - 1) * pageSize);        map.put("pageSize", pageSize);        List<DoingProduct> doingList = doingDao.getProductListByProductIds(map);        PageModel pm = new PageModel();        pm.setCurrentPage(page);        pm.setList(doingList);        pm.setPageSize(pageSize);        pm.setTotalRecord(count);        pm.setTotalPage((count + pageSize - 1) / pageSize);        return pm;    }    @Override    public int isFollowMe(String myFamily, String taFamily) throws AppBusinessException {        Map<String, Object> map = new HashMap<String, Object>();        map.put("myFamily", myFamily);        map.put("taFamily", taFamily);        return doingDao.isFollowMe(map);    }    // 我家发表的    @Override    public PageModel getDoingByMyFamily(String family, Integer page) throws AppBusinessException {        if (Common.empty(page)) {            page = 1;        }        int pageSize = Common.PAGE_SIZE_POSTDOING_MYFAMILY;        Map<String, Object> map = new HashMap<String, Object>();        map.put("family", family);        int count = doingDao.getDoingByMyFamilyCount(map);        map.put("startId", (page - 1) * pageSize);        map.put("pageSize", pageSize);        List<Doing> doingList = doingDao.getDoingByMyFamily(map);        for (Doing d : doingList) {            if (DoingType.FORWARD.getValue().equals(d.getType()) || DoingType.REPLY.getValue().equals(d.getType())                || DoingType.LOVE.getValue().equals(d.getType())) {                Doing rootDoing = getDoingById(d.getRootId());                if (!Common.empty(rootDoing)) {                    d.setRootDoing(rootDoing);                }            } else if (DoingType.PICTORIAL.getValue().equals(d.getType())) {                d.setPictorialObj(pictorialBiz.getPictorialById(d.getPictorial()));            }        }        PageModel pm = new PageModel();        pm.setCurrentPage(page);        pm.setList(doingList);        pm.setPageSize(pageSize);        pm.setTotalRecord(count);        pm.setTotalPage((count + pageSize - 1) / pageSize);        return pm;    }    // 家封面的宝贝相册    @Override    public PageModel getCoverTypeByMyFamily(String family, String coverType, Integer page) throws AppBusinessException {        if (Common.empty(page)) {            page = 1;        }        int pageSize = Common.PAGE_SIZE_POSTDOING_MYFAMILY;        Map<String, Object> map = new HashMap<String, Object>();        map.put("family", family);        map.put("coverType", coverType);        int count = doingDao.getDoingByMyFamilyCount(map);        map.put("startId", (page - 1) * pageSize);        map.put("pageSize", pageSize);        List<Doing> doingList = doingDao.getDoingByMyFamily(map);        for (Doing d : doingList) {            if (DoingType.FORWARD.getValue().equals(d.getType())) {                Doing rootDoing = getDoingById(d.getRootId());                if (!Common.empty(rootDoing)) {                    d.setRootDoing(rootDoing);                }            }        }        PageModel pm = new PageModel();        pm.setCurrentPage(page);        pm.setList(doingList);        pm.setPageSize(pageSize);        pm.setTotalRecord(count);        pm.setTotalPage((count + pageSize - 1) / pageSize);        return pm;    }    @Override    public PageModel getTCoverFeed(String family) throws AppBusinessException {        int page = 1;        if (Common.empty(page)) {            page = 1;        }        int pageSize = Common.PAGE_SIZE_TCOVER_FEED;        Map<String, Object> map = new HashMap<String, Object>();        map.put("family", family);        int count = doingDao.getDoingByMyFamilyCount(map);        map.put("startId", (page - 1) * pageSize);        map.put("pageSize", pageSize);        List<Doing> doingList = doingDao.getDoingByMyFamily(map);        for (Doing d : doingList) {            if (DoingType.FORWARD.getValue().equals(d.getType())) {                Doing rootDoing = getDoingById(d.getRootId());                if (!Common.empty(rootDoing)) {                    d.setRootDoing(rootDoing);                }            }        }        PageModel pm = new PageModel();        pm.setCurrentPage(page);        pm.setList(doingList);        pm.setPageSize(pageSize);        pm.setTotalRecord(count);        pm.setTotalPage((count + pageSize - 1) / pageSize);        return pm;    }    // 提到我家的    @Override    public PageModel getMentionMyFamilyDoing(String family, Integer page) throws AppBusinessException {        if (Common.empty(page)) {            page = 1;        }        int pageSize = Common.PAGE_SIZE_POSTDOING_MYFAMILY;        Map<String, Object> map = new HashMap<String, Object>();        map.put("family", family);        int count = doingDao.getMentionByMyFamilyCount(map);        map.put("startId", (page - 1) * pageSize);        map.put("pageSize", pageSize);        List<Doing> doingList = doingDao.getMentionByMyFamily(map);        setRootDoing(doingList);        PageModel pm = new PageModel();        pm.setCurrentPage(page);        pm.setList(doingList);        pm.setPageSize(pageSize);        pm.setTotalRecord(count);        pm.setTotalPage((count + pageSize - 1) / pageSize);        return pm;    }    //如果微博类型为1、转发，2、喜欢，3、回复就查出微博根doing并设置    private void setRootDoing(List<Doing> doingList) throws AppBusinessException {        for (Doing d : doingList) {            if (DoingType.FORWARD.getValue().equals(d.getType()) || DoingType.LOVE.getValue().equals(d.getType())                || DoingType.REPLY.getValue().equals(d.getType())) {                d.setRootDoing(getDoingById(d.getRootId()));            }        }    }    @Override    public List<DoingProduct> getOtherLoveDoing(String doingId) throws AppBusinessException {        int pageSize = 6;        int page = 1;        Map<String, Object> map = new HashMap<String, Object>();        map.put("startId", (page - 1) * pageSize);        map.put("pageSize", pageSize);        map.put("doingId", doingId);        List<DoingProduct> list = doingDao.getOtherLoveDoing(map);        return list;    }    @Override    public PageModel getForwardDoingList(String rootId, Integer page) throws AppBusinessException {        if (Common.empty(page)) {            page = 1;        }        int pageSize = 10;        Map<String, Object> map = new HashMap<String, Object>();        map.put("rootId", rootId);        int count = doingDao.getForwardDoingListCount(map);        map.put("startId", (page - 1) * pageSize);        map.put("pageSize", pageSize);        List<Doing> doingList = doingDao.getForwardDoingList(map);        PageModel pm = new PageModel();        pm.setCurrentPage(page);        pm.setList(doingList);        pm.setPageSize(pageSize);        pm.setTotalRecord(count);        pm.setTotalPage((count + pageSize - 1) / pageSize);        return pm;    }    // 临时方案    @Override    public PageModel getDoingListByTagBruce(String systemTag, String doingId, Integer size, String time) throws AppBusinessException {        systemTag = Common.notEmptyStr(systemTag) ? "%" + systemTag + "%" : null;        Map<String, Object> map = new HashMap<String, Object>();        map.put("systemTag", systemTag);        map.put("identifier", doingId);        map.put("startId", 0);        map.put("pageSize", size);        map.put("time", DateUtil.parseDate(time));        List<Doing> pList = doingDao.getDoingListByTag(map);        PageModel pm = new PageModel();        pm.setCurrentPage(1);        pm.setList(pList);        pm.setPageSize(1);        pm.setTotalRecord(1);        pm.setTotalPage(1);        return pm;    }    @Override    public PageModel getDoingListByChannelBruce(String channel, String systemTag, Integer size, String time) throws AppBusinessException {        systemTag = Common.notEmptyStr(systemTag) ? "%" + systemTag + "%" : null;        Map<String, Object> map = new HashMap<String, Object>();        map.put("channel", channel);        map.put("systemTag", systemTag);        map.put("startId", 0);        map.put("pageSize", size);        map.put("time", DateUtil.parseDate(time));        List<Doing> pList = doingDao.getDoingListByChannel(map);        PageModel pm = new PageModel();        pm.setCurrentPage(1);        pm.setList(pList);        pm.setPageSize(1);        pm.setTotalRecord(1);        pm.setTotalPage(1);        return pm;    }    //分享微博到新浪微博和腾讯微博    public String shareWeibo(String doingId, String weiboType) throws AppBusinessException {        String url = "";        String doingUrl = "";        String picUrl = "";        String appkey = "";        String title = "";        String nickname = "";        String contentString = "";        List<DoingPicture> doingPictureList = null;        List<DoingProduct> doingProductList = null;        try {            Doing doing = doingDao.getDoingById(doingId);            if (doing == null) {                return null;            }            String type = doing.getType();            if (type.equals(DoingType.REPLY.getValue()) || type.equals(DoingType.POSTS.getValue()) || type.equals(DoingType.WEIBO.getValue())) {                doingPictureList = doing.getDoingPictureList();                doingProductList = doing.getDoingProductList();                nickname = memberBiz.getMemberById(doing.getMember()).getNickname();                contentString = doing.getCutContent();            } else {                Doing rootDoing = getDoingById(doingId);                doingPictureList = rootDoing.getDoingPictureList();                doingProductList = rootDoing.getDoingProductList();                nickname = memberBiz.getMemberById(rootDoing.getMember()).getNickname();                contentString = rootDoing.getCutContent();            }            if (doingProductList.size() > 0) {                picUrl = doingProductList.get(0).getPicUrl();            } else if (doingProductList.size() == 0 && doingPictureList.size() > 0) {                picUrl = doingPictureList.get(0).getImageServer() + doingPictureList.get(0).getPicUrl();            }            doingUrl = server + "dt.htm?id=" + doing.getIdentifier();            if (weiboType.equals(WeiboType.SINA.getValue())) {                title = "分享了@" + Common.SINAWEIBO_NAME_GUOGUOJIE + " 网友@" + nickname + " 的发表的这个内容:" + contentString;                url = "http://service.weibo.com/share/share.php?site=www.guoguojie.com";                appkey = Common.WEIBO_SINA_APP_KEY;            }            if (weiboType.equals(WeiboType.TENCENT.getValue())) {                title = "分享了@" + Common.TENCENTWEIBO_NAME_GUOGUOJIE + " 网友@" + nickname + " 的发表的这个内容:" + contentString;                url = "http://share.v.t.qq.com/index.php?c=share&a=index";                appkey = Common.WEIBO_TENCENT_APP_KEY;            }            title = URLEncoder.encode(title, "UTF-8");            url = url + "&title=" + title + "&url=" + doingUrl + "&appkey=" + appkey + "&pic=" + picUrl;            return url;        } catch (AppBusinessException e) {            e.printStackTrace();        } catch (IOException e) {            e.printStackTrace();        }        return null;    }    @Override    public DoingPicture getPictureById(String id) throws AppBusinessException {        if (Common.empty(id))            return null;        Map<String, Object> map = new HashMap<String, Object>();        map.put("identifier", id);        List<DoingPicture> picList = doingDao.getDoingPictureList(map);        if (picList != null && picList.size() > 0) {            return picList.get(0);        }        return null;    }    @Override    public DoingProduct getProductById(String id) throws AppBusinessException {        if (Common.empty(id))            return null;        Map<String, Object> map = new HashMap<String, Object>();        map.put("identifier", id);        List<DoingProduct> proList = doingDao.getDoingProductList(map);        if (proList != null && proList.size() > 0) {            return proList.get(0);        }        return null;    }    @Override    public int getShareCount(String family) throws AppBusinessException {        Map<String, Object> map = new HashMap<String, Object>();        map.put("family", family);        map.put("type", DoingType.WEIBO.getValue());        return doingDao.getDoingByMyFamilyCount(map);    }    @Override    public PageModel getDoingStat(String type, String startTime, String endTime, Integer page, Integer pageSize, String sort, String orderby)                                                                                                                                             throws AppBusinessException {        if (page == null || page <= 0) {            page = 1;        }        if (Common.empty(pageSize)) {            pageSize = 20;        }        Map<String, Object> map = new HashMap<String, Object>();        map.put("startTime", DateUtil.parseDate(startTime));        map.put("endTime", DateUtil.parseDate(endTime));        map.put("sort", sort);        if (type.equals(DoingType.PICROOT.getValue()) && orderby.equals("replyAmount")) {            orderby = "commentCount";        }        map.put("orderBy", orderby);        map.put("type", type);        int count = doingDao.getDoingStatListCount(map);        map.put("startId", (page - 1) * pageSize);        map.put("pageSize", pageSize);        List<Doing> pList = doingDao.getDoingStatList(map);        PageModel pm = new PageModel();        pm.setCurrentPage(page);        pm.setList(pList);        pm.setPageSize(pageSize);        pm.setTotalRecord(count);        pm.setTotalPage((count + pageSize - 1) / pageSize);        return pm;    }    @Transactional(rollbackForClassName = { "cn.sumpu.app.guoguojie.exception.AppBusinessException" }, timeout = 10)    public void insertDoingStat(String ip, String doing) throws AppBusinessException {        Map<String, Object> map = new HashMap<String, Object>();        map.put("doing", doing);        map.put("viewIP", ip);        DoingStat doingStat = doingDao.getDoingStatByIp(map);        if (Common.empty(doingStat)) {            DoingStat newDoingStat = new DoingStat();            newDoingStat.setIdentifier(identifierBiz.generateId("doing_stat"));            newDoingStat.setDoing(doing);            newDoingStat.setIpViewCount(1);            newDoingStat.setViewIP(ip);            newDoingStat.setLastViewTime(new Date());            doingDao.insertDoingStat(newDoingStat);        } else {            Date date = new Date();            Date lastViewTime = doingStat.getLastViewTime();            int diff = DateUtil.daysOfTwo(date, lastViewTime);            if (diff != 0) {                doingStat.setLastViewTime(new Date());                doingStat.setIpViewCount(doingStat.getIpViewCount() + 1);                doingDao.updateViewDoingIP(doingStat);            }        }    }    //查询这条微博有几个图片    @Override    public int getPicCountByDoing(String doingId) throws AppBusinessException {        Map<String, Object> map = new HashMap<String, Object>();        map.put("doing", doingId);        return doingDao.getPicCountByDoing(map);    }    //查询这条微博有几个商品    @Override    public int getProCountByDoing(String doingId) throws AppBusinessException {        Map<String, Object> map = new HashMap<String, Object>();        map.put("doing", doingId);        return doingDao.getProCountByDoing(map);    }    //查询这条微博画报号    @Override    public String getPictorialByDoing(String doingId) throws AppBusinessException {        return doingDao.getPictorialByDoing(doingId);    }    @Override    public void setLinkUrlTaobao() throws AppBusinessException {        List<DoingProduct> dpList = doingDao.getDoingProductList(null);        for (DoingProduct doingProduct : dpList) {            String oldUrl = doingProduct.getLinkUrl();            String from = doingProduct.getFrom();            if (!Common.empty(from) && from.equals("淘宝")) {                try {                    String newUrl = DoingProductUtil.urlParseTaobao(oldUrl);                    doingProduct.setLinkUrl(newUrl);                    System.out.println("转换后Url:" + newUrl);                    doingDao.updateDoingProduct(doingProduct);                } catch (Exception e) {                    e.printStackTrace();                }            }        }    }    @Override    public int getDoingProCount(String family) throws AppBusinessException {        Map<String, Object> map = new HashMap<String, Object>();        map.put("family", family);        return doingDao.getDoingProCount(map);    }    @Override    public int getDoingPicCount(String family) throws AppBusinessException {        Map<String, Object> map = new HashMap<String, Object>();        map.put("family", family);        return doingDao.getDoingPicCount(map);    }    @Override    public int getMyRelpycCount(String family) throws AppBusinessException {        Map<String, Object> map = new HashMap<String, Object>();        map.put("family", family);        return doingDao.getMyRelpycCount(map);    }    @Override    public List<Doing> getMyRelpy(String family) throws AppBusinessException {        return doingDao.getMyRelpy(family);    }    @Override    public int getMyPictorialBadge(String family) throws AppBusinessException {        return doingDao.getMyPictorialBadge(family);    }    @Override    public DoingProduct getDoingProductById(String id) throws AppBusinessException {        return doingDao.getDoingProductById(id);    }    @Override    public DoingPicture getDoingPictureById(String id) throws AppBusinessException {        return doingDao.getDoingPictureById(id);    }    @Override    public String doingDetail(String doingId, String proId, String picId, HttpServletRequest request) throws AppBusinessException {        Doing doing = null;        DoingProduct doingProduct = null;        DoingPicture doingPicture = null;        if (Common.notEmptyStr(proId)) {            doingProduct = getDoingProductById(proId);            doingId = doingProduct.getDoing();        } else if (Common.notEmptyStr(picId)) {            doingPicture = getDoingPictureById(picId);            doingId = doingPicture.getDoing();        }        doing = getDoingById(doingId);        if (!Common.empty(doing)) {            insertDoingStat(Common.getIp(request), doingId);// 添加ip访问记录            showProPic(proId, picId, request, doing);//显示微博里的产品图还是普通图            request.setAttribute("doing", doing);            // 标签            if (Common.notEmptyStr(doing.getTag())) {                List<String> tagList = substringTime(doing.getTag());                request.setAttribute("tagList", tagList);            }            // 喜欢这个的人还喜欢            List<DoingProduct> otherLoveList = getOtherLoveDoing(doingId);            request.setAttribute("otherLoveList", otherLoveList);            //            familyInfo(request, doing);//发微博的家基本信息            //            //广告位            //            List<CmsContent> adList = cmsContentBiz.getContentList("100000021", 2);            //            request.setAttribute("adList", adList);        }        return "v2/doing/doingProductDetail";    }    /*private void familyInfo(HttpServletRequest request, Doing doing) throws AppBusinessException {        Family family = familyBiz.getFamilyByDoor(doing.getOwner());        List<Member> memberList = memberBiz.getMemberListByDoorplate(doing.getOwner());        family.setMemberList(memberList);        Member member = (Member) request.getSession().getAttribute("member");        int isFollow = 0;        if (doing.getOwner().equals(family.getDoorplate()) && !Common.empty(member)) {            isFollow = isFollowMe(member.getFamily(), doing.getOwner());        }        request.setAttribute("family", family);        request.setAttribute("memberList", family.getMemberList());        request.setAttribute("isFollow", isFollow);    }*/    private void showProPic(String proId, String picId, HttpServletRequest request, Doing doing) {        // 商品图集合        List<DoingProduct> doingProductList = doing.getDoingProductList();        if (doingProductList.size() > 0) {            request.setAttribute("doingProductList", doingProductList);            if (!Common.empty(proId)) {                for (DoingProduct pr : doingProductList) {                    if (pr.getIdentifier().equals(proId)) {                        request.setAttribute("showDoingProduct", pr);                        request.setAttribute("productId", proId);                    }                }            } else if (Common.empty(proId) && Common.empty(picId)) {                request.setAttribute("showDoingProduct", doingProductList.get(0));            }        }        // 微博图集合        List<DoingPicture> doingPictureList = doing.getDoingPictureList();        if (doingPictureList.size() > 0) {            request.setAttribute("doingPictureList", doingPictureList);            if (!Common.empty(picId)) {                for (DoingPicture dp : doingPictureList) {                    if (dp.getIdentifier().equals(picId)) {                        request.setAttribute("showDoingPicture", dp);                        request.setAttribute("pictureId", picId);                    }                }            } else if (doingProductList.size() == 0) {                request.setAttribute("showDoingPicture", doingPictureList.get(0));            }        }    }    // 切分标签    private static List<String> substringTime(String tagStr) {        String s = new String(tagStr);        List<String> list = new ArrayList<String>();        String a[] = s.split(",");        for (int i = 0; i < a.length; i++) {            list.add(a[i]);        }        return list;    }    /**     * author BruceZhang     * @param id	商品ID     * @return	根据商品Id查询产品的所有属性     * @throws AppBusinessException     */    @Override    public DoingProduct getDpById(String id) throws AppBusinessException {        return doingDao.getDpById(id);    }    /**     * author BruceZhang     * @param map	startTime：开始时间 endTime：结束时间 pictorial：所属画报     * @return	查询画报的商品(后台ETAO)     * @throws AppBusinessException     */    @Override    public List<DoingProduct> getProductByPictorial(String startTime, String endTime, String pictorial) throws Exception {        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");        Date st = sdf.parse(startTime);        Date et = sdf.parse(endTime);        Map<String, Object> map = new HashMap<String, Object>();        map.put("startTime", st);        map.put("endTime", et);        map.put("pictorial", pictorial);        return doingDao.getProductByPictorial(map);    }    /**     * author Bruce Zhang     * @param from         来源     * @param originalId   原始ID     * @return 查询这个商品是否被分享过     * @throws AppBusinessException     */    @Override    public DoingProduct getProductContain(String from, String originalId) throws AppBusinessException {        Map<String, Object> map = new HashMap<String, Object>();        map.put("from", from);        map.put("originalId", originalId);        return doingDao.getProductContain(map);    }    /**     * @author BruceZhang     * @param product   商品信息     * @return          切割商品图片并返回商品信息     * @throws Exception     */    @Override    public DoingProduct cutImg(DoingProduct product, String memberId) throws AppBusinessException {        try {            String formateDate = Common.getFormatDate(new Date());            String savePathServer = "pic/doing/" + formateDate + "/" + memberId + "/product";            String uuid = UUID.randomUUID().toString();            String picUrl = product.getPicUrl();            URL urlObj = new URL(picUrl);            URLConnection connection = urlObj.openConnection();            InputStream is = connection.getInputStream();            byte[] b = Common.inputStreamToByte(is);            ImageInfo info = new ImageInfo();            MagickImage image = new MagickImage(info, b);            Dimension imageDim = image.getDimension();            int pWidth = imageDim.width;            int pHeight = imageDim.height;            double zoomW = (double) Common.THUMB_WIDTH_150 / pWidth;            double zoomH = (double) Common.THUMB_HEIGHT_160 / pHeight;            if (zoomW < zoomH) {                // 150                imageBiz.cutImage(b, Common.THUMB_WIDTH_150, -1, savePathServer, uuid + "_thumb.jpg" + "_150x160.jpg");            } else {                // 150                imageBiz.cutImage(b, -1, Common.THUMB_HEIGHT_160, savePathServer, uuid + "_thumb.jpg" + "_150x160.jpg");            }            // 100x100            imageBiz.cutImage(b, Common.THUMB_WIDTH_100, Common.THUMB_HEIGHT_100, savePathServer, uuid + "_thumb.jpg" + "_100x100.jpg");            // 200x200            imageBiz.cutImage(b, Common.THUMB_WIDTH_200, Common.THUMB_HEIGHT_200, savePathServer, uuid + "_thumb.jpg" + "_200x200.jpg");            // 200xXXX            ImageWeb iw = imageBiz.cutImage(b, Common.THUMB_WIDTH_200, -1, savePathServer, uuid + "_thumb.jpg" + "_200xXXX.jpg");            // 320xXXX            imageBiz.cutImage(b, Common.THUMB_WIDTH_320, -1, savePathServer, uuid + "_thumb.jpg" + "_320xXXX.jpg");            // 468xXXX            imageBiz.cutImage(b, Common.ORG_WIDTH_DOING, -1, savePathServer, uuid + "_thumb.jpg" + "_468xXXX.jpg");            product.setImageServer(imageServer);            product.setPicThumb(savePathServer + "/" + uuid + "_thumb.jpg");            // 将宽为200高不定的图的宽高存数据库            product.setHeight200xxx(iw.getHeight());            product.setWidth200xxx(iw.getWidth());            return product;        } catch (Exception e) {            if (logger.isErrorEnabled()) {                logger.error("Cut doing-product image fail", e);            }            throw new AppBusinessException("Cut doing-product image fail", e);        }    }    /**     * @author Bruce Zhang     * @param from         来源     * @param tbks         淘宝客集合     * @return 查询这个商品是否被分享过     * @throws AppBusinessException     */    @Override    public void getProductsContain(String from, List<TaobaokeItem> tbks) throws AppBusinessException {        if (tbks == null || tbks.size() == 0) {            return;        }        String originalIds = "";        for (int i = 0; i < tbks.size(); i++) {            originalIds += "'" + tbks.get(i).getNumIid() + "'";            if ((i + 1) != tbks.size()) {                originalIds += ",";            }        }        originalIds = "(" + originalIds + ")";        Map<String, Object> map = new HashMap<String, Object>();        map.put("from", from);        map.put("originalId", originalIds);        List<DoingProduct> dps = doingDao.getProductsContain(map);        for (int i = 0; i < dps.size(); i++) {            for (int j = 0; j < tbks.size(); j++) {                if (String.valueOf(tbks.get(j).getNumIid()).equals(dps.get(i).getOriginalId())) {                    tbks.remove(j);                }            }        }    }    /**     * author BruceZhang     * @param product   商品     * @return  添加商品     * @throws AppBusinessException     */    @Override    public DoingProduct addProduct(DoingProduct product) throws AppBusinessException {        if (product.getCommission() != null && product.getCommission() > 0) {            topBiz.subscribe(product); //订阅商品变更通知        }        //去除标题中的标签        if (Common.notEmptyStr(product.getName())) {            product.setName(cn.sumpu.toolkit.common.util.Common.filterHtml(product.getName()));        }        doingDao.insertDoingProduct(product);        return product;    }    /**     * author BruceZhang     * @param product   商品     * @return  更新商品     * @throws AppBusinessException     */    @Override    public void updateDoingProduct(DoingProduct product) throws AppBusinessException {        doingDao.updateDoingProduct(product);    }    /**     * @author nick     * @param doingProductTime     * @throws AppBusinessException     * @see cn.sumpu.app.guoguojie.biz.DoingBiz#postDoingProductTime(cn.sumpu.app.guoguojie.domain.DoingProductTime)     */    @Override    public void postDoingProductTime(DoingProductTime doingProductTime) throws AppBusinessException {        boolean flag = checkDoingProductTime(doingProductTime);        if (flag) {// 发布的限时商品不符合规则            if (logger.isDebugEnabled()) {                logger.debug("Doing-product-time exist,can't post!");            }            return;        } else {            doingDao.insertDoingProductTime(doingProductTime);        }    }    /**     * @param doingProductTime     * @return     * @throws AppBusinessException     * @see cn.sumpu.app.guoguojie.biz.DoingBiz#checkDoingProductTime(cn.sumpu.app.guoguojie.domain.DoingProductTime)     */    @Override    public boolean checkDoingProductTime(DoingProductTime doingProductTime) throws AppBusinessException {        if (null == doingProductTime) {            if (logger.isErrorEnabled()) {                logger.error("DoingProductTime is null!");            }            throw new AppBusinessException("DoingProductTime is null!");        }        if (null == doingProductTime.getDoingProductId()) {            if (logger.isErrorEnabled()) {                logger.error("DoingProductTime's doingProductId is null!");            }            throw new AppBusinessException("DoingProductTime's doingProductId is null!");        }        if (null == doingProductTime.getBeginTime()) {            if (logger.isErrorEnabled()) {                logger.error("DoingProductTime's beginTime is null!");            }            throw new AppBusinessException("DoingProductTime's beginTime is null!");        }        if (null == doingProductTime.getEndTime()) {            if (logger.isErrorEnabled()) {                logger.error("DoingProductTime's endTime is null!");            }            throw new AppBusinessException("DoingProductTime's endTime is null!");        }        Map<String, Object> map = new HashMap<String, Object>();        map.put("doingProductId", doingProductTime.getDoingProductId());        map.put("beginTime", doingProductTime.getBeginTime());        map.put("endTime", doingProductTime.getEndTime());        DoingProductTime dpt = doingDao.getDoingProductTime(map);        if (null != dpt) {            return true;        } else {            return false;        }    }    @Override    public PageModel getFanliProduct(Integer page) throws AppBusinessException {        if (page == null || page <= 0) {            page = 1;        }        int pageSize = 21;        Map<String, Object> map = new HashMap<String, Object>();        //返利商品列表        map.put("channel", "f39fb5b1-0f00-4b27-82d3-08b65c1f299e");        int count = doingDao.getFanliProductCount(map);        map.put("startId", (page - 1) * pageSize);        map.put("pageSize", pageSize);        List<DoingProductTime> pList = doingDao.getFanliProduct(map);        PageModel pm = new PageModel();        pm.setCurrentPage(page);        pm.setList(pList);        pm.setPageSize(pageSize);        pm.setTotalRecord(count);        pm.setTotalPage((count + pageSize - 1) / pageSize);        return pm;    }    @Override    public List<DoingProductTime> getEdmProduct() throws AppBusinessException {        int pageSize = 14;        Map<String, Object> map = new HashMap<String, Object>();        //返利商品列表        map.put("channel", "f39fb5b1-0f00-4b27-82d3-08b65c1f299e");        map.put("startId", 1);        map.put("pageSize", pageSize);        List<DoingProductTime> pList = doingDao.getFanliProduct(map);        return pList;    }        public List<DoingProductTime> getFanliProduct(String channel, int nums) throws AppBusinessException {        Map<String, Object> map = new HashMap<String, Object>();        //返利商品列表        map.put("channel", channel);        map.put("startId", 0);        map.put("pageSize", nums);        List<DoingProductTime> pList = doingDao.getFanliProduct(map);        return pList;    }    /**     * author BruceZhang     * @param pid   商品ID     * @param request     * 商品底层页方法     */    @Override    public void productDetail(String pid, HttpServletRequest request) throws AppBusinessException {        DoingProduct product = getDpById(pid);         if (Common.empty(product)) {            return;        }        Doing doing = getDoingById(product.getDoing());        //查询实时返利        TaobaokeItem taobao = topBiz.convertTaobaoke("guoguojie", product.getOriginalId());        if (taobao == null) {            product.setCommission(0D);        } else {            product.setCommission(taobao.getCommission() == null ? 0 : Double.valueOf(taobao.getCommission()));        }        Double commission = product.getCommission();        DoingProductTime dpt = getHasProductTime(pid);        product.setDoingProductTime(dpt);        double guoguojieCommissionMin = appconfBiz.getGuoguojieCommissionMin();        if (null != commission && commission > 0) {            double guoguojieCommission;            if (null != dpt) {                guoguojieCommission = product.getPrice() * dpt.getGuoguojieCommissionRate();                if (guoguojieCommission > guoguojieCommissionMin) {                    request.setAttribute("guoguojieCommissionDisplay", "gcd");                }            } else {                guoguojieCommission = commission * appconfBiz.getGuoguojieCommissionRate();                if (guoguojieCommission > guoguojieCommissionMin) {                    request.setAttribute("guoguojieCommissionDisplay", "gcd");                }            }            request.setAttribute("guoguojieCommission", guoguojieCommission);        }        //浏览量+1        product.setViewAmount(1);        updateDoingProduct(product);        request.setAttribute("product", product);        request.setAttribute("doing", doing);        PageModel pageModel = tagBiz.getProductByTags(getTags(tagBiz.getTagByDoing(doing.getIdentifier())));        request.setAttribute("pageModel", pageModel);    }    private String getTags(List<String> tagList) {        if (tagList == null || tagList.size() == 0) {            return "('')";        }        String tags = "";        for (int i = 0; i < tagList.size(); i++) {            String t = tagList.get(i);            if (i == 0) {                tags += "(";            }            tags += "'" + t;            if (i == (tagList.size() - 1)) {                tags += "')";            } else {                tags += "',";            }        }        return tags;    }    @Override    public PageModel getProductByCondition(String id, String name, String startTime, String endTime, Integer page) throws AppBusinessException, ParseException {        int pageSize = 20;        if (page == null || page <= 0) {            page = 1;        }        Map<String, Object> map = new HashMap<String, Object>();        if (!StringUtils.isEmpty(id))            map.put("identifier", id);        if (!StringUtils.isEmpty(name))            map.put("name", "%" + name + "%");        if (!StringUtils.isEmpty(startTime))            map.put("startTime", Common.parseDate(startTime, "yyyy-MM-dd HH:mm:ss"));        if (!StringUtils.isEmpty(endTime))            map.put("endTime", Common.parseDate(endTime, "yyyy-MM-dd HH:mm:ss"));        int count = doingDao.getDoingProductListCount(map);        map.put("startId", (page - 1) * pageSize);        map.put("pageSize", pageSize);        List<DoingProduct> pList = doingDao.getDoingProductList(map);        PageModel pm = new PageModel();        pm.setCurrentPage(page);        pm.setList(pList);        pm.setPageSize(pageSize);        pm.setTotalRecord(count);        pm.setTotalPage((count + pageSize - 1) / pageSize);        return pm;    }    /**     * author BruceZhang     * @param love 喜欢        * 更新微博的量值(+1)     * @throws AppBusinessException     */    @Override    public void updateDoingAdd(String Doing, Integer love) throws AppBusinessException {        Map<String, Object> map = new HashMap<String, Object>();        map.put("identifier", Doing);        map.put("loveAmount", love);        doingDao.updateDoingAdd(map);    }    /**     * @param productId     * @return     * @throws AppBusinessException     * @see cn.sumpu.app.guoguojie.biz.DoingBiz#getHasProductTime(java.lang.String)     */    @Override    public DoingProductTime getHasProductTime(String productId) throws AppBusinessException {        return doingDao.getHasProductTime(productId);    }    //查询微博    @Override    public List<Doing> getDoingBruce(String time) throws AppBusinessException {        Map<String, Object> map = new HashMap<String, Object>();        map.put("time", DateUtil.parseDate(time));        return doingDao.getDoingBruce(map);    }    //查询商品    @Override    public List<DoingProduct> getProductBruce(String time) throws AppBusinessException {        Map<String, Object> map = new HashMap<String, Object>();        map.put("time", DateUtil.parseDate(time));        return doingDao.getProductBruce(map);    }    //修改数量    @Override    public void updateNumberBruce(String type, String time, Integer number) throws AppBusinessException {        if ("doing_love".equals(type)) {            List<Doing> l = getDoingBruce(time);            for (Doing d : l) {                updateDoingAdd(d.getIdentifier(), new Random().nextInt(number) + 1);            }        } else if ("product_view".equals(type)) {            List<DoingProduct> l = getProductBruce(time);            for (DoingProduct p : l) {                p.setViewAmount(new Random().nextInt(number) + 1);                updateDoingProduct(p);            }        } else if ("discuss_view".equals(type)) {            List<Discuss> l = discussBiz.getDiscussBruce(time);            for (Discuss d : l) {                d.setVisitAmout(new Random().nextInt(number) + 1);                discussBiz.updateDiscussAdd(d);            }        }    }}